import request from "@/util/request";

/**
 * 获取参数项与值
 */
export const listAllParamItemWithValue = () => {
    return request({
        url: '/param/item/listAll',
        method: 'GET',
        headers: {
            'token': localStorage.getItem('token')
        }
    });
};

/**
 * 添加参数项
 */
export const addParamItem = (data: {
    name: string;
    type: number;
    isRequired: number;
    sort: number;
}) => {
    return request({
        url: '/param/item/add',
        method: 'POST',
        headers: {
            'token': localStorage.getItem('token')
        },
        data
    });
};

/**
 * 删除参数项
 */
export const delParamItem = (id: number) => {
    return request({
        url: '/param/item/del',
        method: 'GET',
        headers: {
            'token': localStorage.getItem('token')
        },
        params: {
            "id": id
        }
    });
};

/**
 * 修改参数项
 */
export const modifyParamItem = (data: {
    id: number;
    name: string;
    type: number;
    isRequired: number;
    sort: number;
}) => {
    return request({
        url: '/param/item/modify',
        method: 'POST',
        headers: {
            'token': localStorage.getItem('token')
        },
        data
    });
};

/**
 * 添加参数值
 */
export const addParamValue = (data: {
    paramItemId: number;
    value: string;
    priceOffset: number;
    stock: number;
}) => {
    return request({
        url: '/param/value/add',
        method: 'POST',
        headers: {
            'token': localStorage.getItem('token')
        },
        data
    });
};

/**
 * 删除参数值
 */
export const delParamValue = (id: number) => {
    return request({
        url: '/param/value/del',
        method: 'GET',
        headers: {
            'token': localStorage.getItem('token')
        },
        params: {
            "id": id
        }
    });
};

/**
 * 修改参数值
 */
export const modifyParamValue = (data: {
    id: number;
    paramItemId: number;
    value: string;
    priceOffset: number;
    stock: number;
}) => {
    return request({
        url: '/param/value/modify',
        method: 'POST',
        headers: {
            'token': localStorage.getItem('token')
        },
        data
    });
};
